/*
* 
* jsddate v0.23
* Setting Orange, Confusion 29, YOLD 3176 
* written by Pope Sulla out of the Pit (euronymous@gmail.com)
* stole a lot from irssi_ddate (http://blea.ch/wiki/index.php/Ddate)
* (K)All Rites reversed - copy what you want
* 
* If no arguments are passed, it is usually the actual day, but who knows
*/

function ddate (day, mon, year){

// for the lazy ones without parameters
    var now = new Date();
    
    if (typeof day == 'undefined') {
        var day = now.getDate();
    }
    
    if (typeof mon == 'undefined') {
        var mon = now.getMonth() + 1;
    }
    
    if (typeof year == 'undefined') {
        var year = now.getFullYear();
    }


// give us the day of the year
    daysofmonths = new Array( 0, 31, 59, 90, 120, 151, 181, 212, 242, 273, 303, 334);
    
    if (year % 4 == 0){
        if (mon > 2){
            var dayofyear = daysofmonths[mon - 1] + day + 1; 
        }
    } else {
        var dayofyear = daysofmonths[mon - 1] + day;        
    }     

// year is pretty easy    
    var ddyear = year + 1166;

// here comes the season    
    var dseason = Math.floor((dayofyear - 1) / 73);
    
    seasons = new Array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath");
    
    var ddseason = seasons[dseason];


// the weekday  
    
    var dweekday = ((dayofyear - 1) % 5);
  
    weekdays = new Array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
    
    var ddweekday = weekdays[dweekday];

// the discordian day of the season
    
    var dday = ((dayofyear - 1) % 73) + 1;    


// the holydays
    holydays = new Array("Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay", "Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux");
    
    if (dday == 5) {
        var dholyday = holydays[dseason];
        var fnord = 1;
    };
    
    if (dday == 50) {
        var dholyday = holydays[dseason + 5];
        var fnord = 1;
    };

// St. Tibs is special special    
    if (day == 29) {
        if (mon == 2 ) {
            var fnord = 2;            
        }
    };    

// and the bunghole     
    if (fnord == 1) {
        document.write(' ' + ddweekday + ', ' + ddseason + ' ' + dday + ' , YOLD ' + ddyear + ' -- ' + dholyday + ' ');
        } else if (fnord == 2){
            document.write('Saint Tib\'s Day, ' + ddyear + ' YOLD ');    
        } else {
            document.write(' ' + ddweekday + ', ' + ddseason + ' ' + dday + ', YOLD ' + ddyear + ' ');
        }
};